/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * MainWindow.java
 *
 * Created on 10/06/2011, 08:04:50 PM
 */

package GUI.ATTENDANT;

import GUI.Customer.Server;
import Procedures.DBConection;
import Procedures.LoanTable;
import entities.Asignature;
import entities.Computer;
import entities.ComputerRoom;
import entities.Especiality;
import entities.User;
import java.awt.FlowLayout;
import javax.swing.JPanel;

/**
 *
 * @author SIX-14
 */
public class MainWindow extends javax.swing.JFrame {

    /** Creates new form MainWindow */

    public MainWindow() {
        initComponents();
    }

    private Server server;

    public Server getServer() {
        return server;
    }

    public void setServer(Server server) {
        this.server = server;
    }


    public MainWindow(DBConection myConection) {
        initComponents();
        this.setLayout(new FlowLayout());
        setMyConection(myConection);
        this.loanTable= new LoanTable();
        server= new Server();
        server.startServer();


    }

    private LoanTable loanTable;

    public LoanTable getLoanTable() {
        return loanTable;
    }

    public void setLoanTable(LoanTable loanTable) {
        this.loanTable = loanTable;
    }
    private DBConection myConection;


    public DBConection getMyConection() {
        return myConection;
    }

    public void setMyConection(DBConection myConection) {
        this.myConection = myConection;
    }

    public void addPanel(JPanel panel){
        this.getContentPane().removeAll();
        this.add(panel);
        this.pack();
    }


    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPopupMenu1 = new javax.swing.JPopupMenu();
        jMenuBar1 = new javax.swing.JMenuBar();
        jMenu1 = new javax.swing.JMenu();
        addStudent = new javax.swing.JMenuItem();
        jMenuItem2 = new javax.swing.JMenuItem();
        jMenuItem3 = new javax.swing.JMenuItem();
        jMenuItem4 = new javax.swing.JMenuItem();
        jMenuItem5 = new javax.swing.JMenuItem();
        jMenu2 = new javax.swing.JMenu();
        jMenuItem8 = new javax.swing.JMenuItem();
        jMenuItem9 = new javax.swing.JMenuItem();
        jMenuItem10 = new javax.swing.JMenuItem();
        jMenuItem11 = new javax.swing.JMenuItem();
        jMenuItem12 = new javax.swing.JMenuItem();
        jMenu3 = new javax.swing.JMenu();
        jMenuItem15 = new javax.swing.JMenuItem();
        jMenuItem16 = new javax.swing.JMenuItem();
        jMenuItem17 = new javax.swing.JMenuItem();
        jMenuItem18 = new javax.swing.JMenuItem();
        jMenuItem19 = new javax.swing.JMenuItem();
        jMenu4 = new javax.swing.JMenu();
        jMenu6 = new javax.swing.JMenu();
        jMenuItem1 = new javax.swing.JMenuItem();
        jMenuItem6 = new javax.swing.JMenuItem();
        jMenuItem23 = new javax.swing.JMenuItem();
        jMenu5 = new javax.swing.JMenu();
        jMenuItem24 = new javax.swing.JMenuItem();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setTitle("Administracion");
        addWindowListener(new java.awt.event.WindowAdapter() {
            public void windowClosing(java.awt.event.WindowEvent evt) {
                formWindowClosing(evt);
            }
        });

        jMenu1.setActionCommand("Agregar");
        jMenu1.setLabel("Agregar");

        addStudent.setText("Usuario");
        addStudent.setCursor(new java.awt.Cursor(java.awt.Cursor.DEFAULT_CURSOR));
        addStudent.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mousePressed(java.awt.event.MouseEvent evt) {
                addStudentMousePressed(evt);
            }
        });
        jMenu1.add(addStudent);

        jMenuItem2.setLabel("Sala");
        jMenuItem2.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mousePressed(java.awt.event.MouseEvent evt) {
                jMenuItem2MousePressed(evt);
            }
        });
        jMenu1.add(jMenuItem2);

        jMenuItem3.setText("Computadora");
        jMenuItem3.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mousePressed(java.awt.event.MouseEvent evt) {
                jMenuItem3MousePressed(evt);
            }
        });
        jMenu1.add(jMenuItem3);

        jMenuItem4.setText("Materia");
        jMenuItem4.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mousePressed(java.awt.event.MouseEvent evt) {
                jMenuItem4MousePressed(evt);
            }
        });
        jMenu1.add(jMenuItem4);

        jMenuItem5.setText("Especialidad");
        jMenuItem5.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mousePressed(java.awt.event.MouseEvent evt) {
                jMenuItem5MousePressed(evt);
            }
        });
        jMenu1.add(jMenuItem5);

        jMenuBar1.add(jMenu1);

        jMenu2.setLabel("Modificar");

        jMenuItem8.setText("Usuario");
        jMenuItem8.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mousePressed(java.awt.event.MouseEvent evt) {
                jMenuItem8MousePressed(evt);
            }
        });
        jMenu2.add(jMenuItem8);

        jMenuItem9.setText("Sala");
        jMenuItem9.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mousePressed(java.awt.event.MouseEvent evt) {
                jMenuItem9MousePressed(evt);
            }
        });
        jMenu2.add(jMenuItem9);

        jMenuItem10.setText("Computadora");
        jMenuItem10.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mousePressed(java.awt.event.MouseEvent evt) {
                jMenuItem10MousePressed(evt);
            }
        });
        jMenu2.add(jMenuItem10);

        jMenuItem11.setText("Materia");
        jMenuItem11.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mousePressed(java.awt.event.MouseEvent evt) {
                jMenuItem11MousePressed(evt);
            }
        });
        jMenu2.add(jMenuItem11);

        jMenuItem12.setText("Especialidad");
        jMenuItem12.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mousePressed(java.awt.event.MouseEvent evt) {
                jMenuItem12MousePressed(evt);
            }
        });
        jMenu2.add(jMenuItem12);

        jMenuBar1.add(jMenu2);

        jMenu3.setLabel("Eliminar");
        jMenu3.setMaximumSize(new java.awt.Dimension(59, 32767));
        jMenu3.setPreferredSize(new java.awt.Dimension(59, 19));

        jMenuItem15.setText("Usuario");
        jMenuItem15.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mousePressed(java.awt.event.MouseEvent evt) {
                jMenuItem15MousePressed(evt);
            }
        });
        jMenu3.add(jMenuItem15);

        jMenuItem16.setText("Sala");
        jMenuItem16.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mousePressed(java.awt.event.MouseEvent evt) {
                jMenuItem16MousePressed(evt);
            }
        });
        jMenu3.add(jMenuItem16);

        jMenuItem17.setText("Computadora");
        jMenuItem17.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mousePressed(java.awt.event.MouseEvent evt) {
                jMenuItem17MousePressed(evt);
            }
        });
        jMenu3.add(jMenuItem17);

        jMenuItem18.setText("Materia");
        jMenuItem18.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mousePressed(java.awt.event.MouseEvent evt) {
                jMenuItem18MousePressed(evt);
            }
        });
        jMenu3.add(jMenuItem18);

        jMenuItem19.setText("Especialidad");
        jMenuItem19.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mousePressed(java.awt.event.MouseEvent evt) {
                jMenuItem19MousePressed(evt);
            }
        });
        jMenu3.add(jMenuItem19);

        jMenuBar1.add(jMenu3);

        jMenu4.setLabel("Prestamos");

        jMenu6.setText("Computadora");

        jMenuItem1.setText("por lectora");
        jMenuItem1.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mousePressed(java.awt.event.MouseEvent evt) {
                jMenuItem1MousePressed(evt);
            }
        });
        jMenu6.add(jMenuItem1);

        jMenuItem6.setText("Manual");
        jMenuItem6.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mousePressed(java.awt.event.MouseEvent evt) {
                jMenuItem6MousePressed(evt);
            }
        });
        jMenu6.add(jMenuItem6);

        jMenu4.add(jMenu6);

        jMenuItem23.setLabel("Sala");
        jMenuItem23.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mousePressed(java.awt.event.MouseEvent evt) {
                jMenuItem23MousePressed(evt);
            }
        });
        jMenu4.add(jMenuItem23);

        jMenuBar1.add(jMenu4);

        jMenu5.setText("Administracion");
        jMenu5.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jMenu5MouseClicked(evt);
            }
        });

        jMenuItem24.setText("Reportes");
        jMenu5.add(jMenuItem24);

        jMenuBar1.add(jMenu5);

        setJMenuBar(jMenuBar1);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 400, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 279, Short.MAX_VALUE)
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void addStudentMousePressed(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_addStudentMousePressed
        addPanel(new UserGui(getMyConection(),1,this,new User()));
    }//GEN-LAST:event_addStudentMousePressed

    private void jMenuItem8MousePressed(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jMenuItem8MousePressed
        addPanel(new FinderUser(getMyConection(),2,this));
    }//GEN-LAST:event_jMenuItem8MousePressed

    private void jMenuItem15MousePressed(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jMenuItem15MousePressed
        addPanel(new FinderUser(getMyConection(),3,this));
    }//GEN-LAST:event_jMenuItem15MousePressed

    private void jMenuItem5MousePressed(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jMenuItem5MousePressed
        addPanel(new EspecialityGui(getMyConection(), 1, new Especiality()));
    }//GEN-LAST:event_jMenuItem5MousePressed

    private void jMenuItem12MousePressed(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jMenuItem12MousePressed
        addPanel(new FinderOption(getMyConection(), 2, this,4, "Escriba el código de la Especialidad a buscar" ));
    }//GEN-LAST:event_jMenuItem12MousePressed

    private void jMenuItem19MousePressed(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jMenuItem19MousePressed
        addPanel(new FinderOption(getMyConection(), 3, this, 4, "Escriba el código de la Especialidad a buscar"));
    }//GEN-LAST:event_jMenuItem19MousePressed

    private void jMenuItem4MousePressed(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jMenuItem4MousePressed
        addPanel(new AsignatureGui(getMyConection(), 1, new Asignature()));
    }//GEN-LAST:event_jMenuItem4MousePressed

    private void jMenuItem11MousePressed(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jMenuItem11MousePressed
        addPanel(new FinderOption(getMyConection(), 2, this,3,"Escriba el código de la Materia a buscar"));
    }//GEN-LAST:event_jMenuItem11MousePressed

    private void jMenuItem18MousePressed(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jMenuItem18MousePressed
        addPanel(new FinderOption(getMyConection(), 3, this, 3,"Escriba el código de la Materia a buscar"));// TODO add your handling code here:
    }//GEN-LAST:event_jMenuItem18MousePressed

    private void jMenuItem2MousePressed(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jMenuItem2MousePressed
        addPanel(new ComputerRoomGui(getMyConection(), 1, new ComputerRoom()));
    }//GEN-LAST:event_jMenuItem2MousePressed

    private void jMenuItem9MousePressed(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jMenuItem9MousePressed
        addPanel(new FinderOption(getMyConection(), 2, this, 1, "Escriba la letra de la Sala que desee buscar"));
    }//GEN-LAST:event_jMenuItem9MousePressed

    private void jMenuItem16MousePressed(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jMenuItem16MousePressed
        addPanel(new FinderOption(getMyConection(), 3, this, 1, "Escriba la letra de la Sala que desee buscar:"));// TODO add your handling code here:
    }//GEN-LAST:event_jMenuItem16MousePressed

    private void jMenuItem3MousePressed(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jMenuItem3MousePressed
        addPanel(new ComputerGui(getMyConection(), 1, new  Computer(), this));
    }//GEN-LAST:event_jMenuItem3MousePressed

    private void jMenuItem10MousePressed(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jMenuItem10MousePressed
        addPanel(new FinderOption(getMyConection(), 2, this,2,"Escriba el numero de Computadora a buscar"));
    }//GEN-LAST:event_jMenuItem10MousePressed

    private void jMenuItem17MousePressed(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jMenuItem17MousePressed
        addPanel(new FinderOption(getMyConection(), 3, this,2,"Escriba el numero de Computadora a buscar"));
    }//GEN-LAST:event_jMenuItem17MousePressed

    private void jMenuItem1MousePressed(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jMenuItem1MousePressed
       LoanComputerAutomatic loancomputer = new LoanComputerAutomatic(getMyConection(),getLoanTable(), getServer());
       loancomputer.setVisible(true);
    }//GEN-LAST:event_jMenuItem1MousePressed

    private void jMenuItem6MousePressed(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jMenuItem6MousePressed
        addPanel( new LoanComputerManual(getMyConection(), this,getLoanTable(), getServer()));
    }//GEN-LAST:event_jMenuItem6MousePressed

    private void jMenuItem23MousePressed(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jMenuItem23MousePressed
        addPanel(new LoanComputerRoom(getMyConection(), this, getLoanTable(), getServer()));
    }//GEN-LAST:event_jMenuItem23MousePressed

    private void formWindowClosing(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_formWindowClosing
        System.out.println("bye");
        //cerrar los clientes
       //
    }//GEN-LAST:event_formWindowClosing

    private void jMenu5MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jMenu5MouseClicked
        Reports reports = new Reports(myConection, this);
        this.addPanel(reports);

    }//GEN-LAST:event_jMenu5MouseClicked

    /**
    * @param args the command line arguments
    */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {


                new MainWindow().setVisible(true);
            }
        });
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JMenuItem addStudent;
    private javax.swing.JMenu jMenu1;
    private javax.swing.JMenu jMenu2;
    private javax.swing.JMenu jMenu3;
    private javax.swing.JMenu jMenu4;
    private javax.swing.JMenu jMenu5;
    private javax.swing.JMenu jMenu6;
    private javax.swing.JMenuBar jMenuBar1;
    private javax.swing.JMenuItem jMenuItem1;
    private javax.swing.JMenuItem jMenuItem10;
    private javax.swing.JMenuItem jMenuItem11;
    private javax.swing.JMenuItem jMenuItem12;
    private javax.swing.JMenuItem jMenuItem15;
    private javax.swing.JMenuItem jMenuItem16;
    private javax.swing.JMenuItem jMenuItem17;
    private javax.swing.JMenuItem jMenuItem18;
    private javax.swing.JMenuItem jMenuItem19;
    private javax.swing.JMenuItem jMenuItem2;
    private javax.swing.JMenuItem jMenuItem23;
    private javax.swing.JMenuItem jMenuItem24;
    private javax.swing.JMenuItem jMenuItem3;
    private javax.swing.JMenuItem jMenuItem4;
    private javax.swing.JMenuItem jMenuItem5;
    private javax.swing.JMenuItem jMenuItem6;
    private javax.swing.JMenuItem jMenuItem8;
    private javax.swing.JMenuItem jMenuItem9;
    private javax.swing.JPopupMenu jPopupMenu1;
    // End of variables declaration//GEN-END:variables

}
